
$(function () {
    var get = $(".get");
    var emial = $('#email');
    var phone =$('#phone');
    var next = $('.next');
    emial.focus(function () {
        $('.toolphone').css("display","none");
        $('.toolphone2').css("display","none");
    });
    get.click(function () {
        if (emial.val()==""){
            $('.toolphone').css("display","block");
        } else{
            $.ajax({
                type: "POST",
                url:"ajaxFindPwd",
                dataType:"text",
                data:{"phone":phone.val(),"email":emial.val()},
                success:function (resp) {
                    if (resp=="false"){
                        $('.toolphone2').css("display","block")
                    }else {
                        $.ajax({
                            type: "POST",
                            url:"ajaxYanZhenMa",
                            dataType:"text",
                            data:{"code":emial.val(),"email":emial.val()},
                            success:function (resp) {
                                alert(resp)
                                changeSendEmailButton();
                            }
                        })


                    }
                }
            })
        }
    })

 next.click(function () {
     if ($('#code_phone').val()=="") {
         $('.toolnum2').css("display","block");
     }else {
         $.ajax({
             type: "POST",
             url:"ajaxYanZhenMa2",
             dataType:"text",
             data:{"code":emial.val(),"codeval":$("#code_phone").val()},
             success:function (resp) {
                 if (resp=="success"){
                     $('.form').submit();
                 }else {
                     $('.toolnum').css("display","block");
                 }
             }
         })
     }
 })


    function changeSendEmailButton() {
        var time = setInterval(change, 1000);
        var count = 120;

        function change() {
            count--;
            if (count == 0){
                get.removeAttr('disabled');
                count = 120;
                get.val('发送验证码');
                clearInterval(time);
            } else {
                get.attr('disabled', true);
                get.val('还剩'+count+'秒');
            }
        }
    }
})